<?php
/**
 * Created by PhpStorm.
 * User: sunzexin
 * Date: 2018/1/29
 * Time: 11:28
 */

namespace App\Http\Controllers\MiniProgramAdmin;

use App\Http\Logics\MiniProgramAdmin\CashCouponLogic;
use App\Http\Traits\CashCouponTrait;
use App\Http\Controllers\BaseController;
class CashCouponController extends BaseController
{
    use CashCouponTrait;

    /**
     * @SWG\Post(
     *     path="/cashCoupon/create",
     *     tags={"CashCoupon"},
     *     description="创建代金券",
     *     operationId="createCashCoupon",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="name",
     *         in="query",
     *         description="代金券名称",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="description",
     *         in="query",
     *         description="代金券描述",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="num",
     *         in="query",
     *         description="代金券数量",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="denomination",
     *         in="query",
     *         description="代金券面额",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="limit",
     *         in="query",
     *         description="购买商品费用最低限度",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="start_time",
     *         in="query",
     *         description="代金券有效期开始时间",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="end_time",
     *         in="query",
     *         description="代金券有效期结束时间",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createCashCoupon()
    {
        $key = $this->key;
        $name = $this->name;
        $description = $this->description;
        $num = $this->num;
        $limit = $this->limit;
        $denomination = $this->denomination;
        $start_time = $this->start_time;
        $end_time = $this->end_time;
        $data = [
            'key' => $key,
            'name' => $name,
            'description' => $description,
            'num' => $num,
            'denomination' => $denomination,
            'limit' => $limit,
            'start_time' => $start_time,
            'end_time' => $end_time
        ];
        $response = CashCouponLogic::createCashCoupon($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/cashCoupon/list",
     *     tags={"CashCoupon"},
     *     description="获取代金券列表",
     *     operationId="getCashCouponList",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="key",
     *         in="query",
     *         description="合作者key",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getCashCouponList()
    {
        $key = $this->key;
        $data = [
            'key' => $key
        ];
        $response = CashCouponLogic::getCashCouponList($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/cashCoupon/delete",
     *     tags={"CashCoupon"},
     *     description="删除代金券",
     *     operationId="deleteCashCoupon",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cash_coupon_id",
     *         in="query",
     *         description="代金券ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function deleteCashCoupon()
    {
        $cash_coupon_id = $this->cash_coupon_id;
        $data = [
            'cash_coupon_id' => $cash_coupon_id
        ];
        $response = CashCouponLogic::deleteCashCoupon($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Post(
     *     path="/cashCoupon/destroy",
     *     tags={"CashCoupon"},
     *     description="代金券核销",
     *     operationId="destroyCashCoupon",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cash_coupon_id",
     *         in="query",
     *         description="代金券ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Parameter(
     *         name="user_id",
     *         in="query",
     *         description="用户ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function destroyCashCoupon()
    {
        $cash_coupon_id = $this->cash_coupon_id;
        $user_id = $this->user_id;
        $data = [
            'cash_coupon_id' => $cash_coupon_id,
            'user_id' => $user_id
        ];
        $response = CashCouponLogic::destroyCashCoupon($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/cashCoupon/detail",
     *     tags={"CashCoupon"},
     *     description="代金券详情",
     *     operationId="getCashCouponDetail",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cash_coupon_id",
     *         in="query",
     *         description="代金券ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function getCashCouponDetail()
    {
        $cash_coupon_id = $this->cash_coupon_id;
        $data = [
            'cash_coupon_id' => $cash_coupon_id
        ];
        $response = CashCouponLogic::getCashCouponDetail($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }

    /**
     * @SWG\Get(
     *     path="/cashCoupon/createPoster",
     *     tags={"CashCoupon"},
     *     description="创建代金券的分享海报",
     *     operationId="createCashCouponPoster",
     *     produces={"application/json", "application/xml", "text/xml", "text/html"},
     *     @SWG\Parameter(
     *         name="loginSession",
     *         in="query",
     *         description="验证秘钥",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="page",
     *         in="query",
     *         description="小程序页面路径",
     *         required=true,
     *         type="string"
     *     ),
     *     @SWG\Parameter(
     *         name="cash_coupon_id",
     *         in="query",
     *         description="代金券ID",
     *         required=true,
     *         type="integer",
     *         format="int32"
     *     ),
     *     @SWG\Response(
     *         response=200,
     *         description="pet response"
     *     )
     * )
     */
    public function createCashCouponPoster()
    {
        $page = $this->page;
        $cash_coupon_id = $this->cash_coupon_id;
        $data = [
            'page' => $page,
            'cash_coupon_id' => $cash_coupon_id
        ];
        $response = CashCouponLogic::createCashCouponPoster($data);
        if ($response->code){
            return $this->response($response->code, $response->message);
        }
        return $this->response($response->code, $response->message, $response->data);
    }
}